package com.dt.platform.generator.module.hr;


import com.dt.platform.constants.db.HrTables;
import com.dt.platform.constants.enums.hr.LearnTaskStatusEnum;
import com.dt.platform.domain.hr.Learn;
import com.dt.platform.domain.hr.LearnRelease;
import com.dt.platform.generator.config.Config;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;


public class ALeanTaskGtr extends BaseCodeGenerator {
    public ALeanTaskGtr() {
        super(HrTables.HR_LEARN_TASK.$TABLE,"811268060357853184");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(HrTables.HR_LEARN_TASK.ID).basic().hidden(true);

        cfg.getPoClassFile().addSimpleProperty(Employee.class,"user","user","user");
        cfg.getPoClassFile().addSimpleProperty(String.class,"queryRole","queryRole","queryRole");
        cfg.getPoClassFile().addSimpleProperty(Learn.class,"learn","learn","learn");
        cfg.getPoClassFile().addSimpleProperty(LearnRelease.class,"learnRelease","learnRelease","learnRelease");

        cfg.view().field(HrTables.HR_LEARN_TASK.NAME).form().validate().required();
        cfg.view().field(HrTables.HR_LEARN_TASK.START_TIME).form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").search().range();
        cfg.view().field(HrTables.HR_LEARN_TASK.FINISH_TIME).form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd HH:mm:ss").search().range();
        cfg.view().field(HrTables.HR_LEARN_TASK.CREATE_TIME).form().dateInput().type(DatePickerType.datetime).format("yyyy-MM-dd").search().range();

        cfg.view().field(HrTables.HR_LEARN_TASK.NAME).search().fuzzySearch();

        cfg.view().search().inputLayout(
                new Object[]{
                        HrTables.HR_LEARN_TASK.STATUS,
                        HrTables.HR_LEARN_TASK.USER_ID,
                        HrTables.HR_LEARN_TASK.NAME,
                        HrTables.HR_LEARN_TASK.CREATE_TIME,
                }
        );

        cfg.view().field(HrTables.HR_LEARN_TASK.USER_ID).table().fillBy("user","name");
        cfg.view().field(HrTables.HR_LEARN_TASK.USER_ID).form().readOnly().form()
                .button().chooseEmployee(true).search().selectMuliti(false);

        cfg.view().list().disableBatchDelete();
      //  cfg.view().field(HrTables.HR_LEARN_TASK.START_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.LEARN_ID).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.UPDATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.UPDATE_TIME).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.CREATE_BY).form().table().disable(true);
        cfg.view().field(HrTables.HR_LEARN_TASK.LEARN_RELEASE_ID).form().table().disable(true);

        cfg.view().field(HrTables.HR_LEARN_TASK.STATUS).form()
              .radioBox().enumType(LearnTaskStatusEnum.class);


        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);


        cfg.view().search().rowsDisplay(1);
        cfg.view().formWindow().width("80%");;
        cfg.view().formWindow().bottomSpace(150);


        cfg.view().form().addGroup(null,
                new Object[] {
                        HrTables.HR_LEARN_TASK.STATUS,
                        HrTables.HR_LEARN_TASK.START_TIME,
                        HrTables.HR_LEARN_TASK.FINISH_TIME,
                }
        );

        cfg.view().list().addJsVariable("LEARN_RELEASE_ID","[[${learnReleaseId}]]","learnReleaseId");
        cfg.view().list().addJsVariable("ROLE","[[${role}]]","role");

        cfg.view().list().operationColumn().addActionButton("学习","start","start");


        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setBpmEventAdaptor(WriteMode.COVER_EXISTS_FILE)
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE) //列表HTML页
                .setExtendJsFile(WriteMode.IGNORE);
        //生成代码
        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        ALeanTaskGtr g=new ALeanTaskGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
       // System.out.println("############"+g.getTablePrefix());
       // g.removeByBatchId("801716675761143808");
      //  //生成菜单
       //g.generateMenu(LearnTaskServiceProxy.class, LearnTaskPageController.class);
    }
}
